{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字典的方法 EXCEL\n",
    "---\n",
    "\n",
    "# 组合数据类型有三种\n",
    "> 1.集合\n",
    "> 2.序列-----分为三种（1.字符串 2.列表 3.元组）\n",
    "> 3.字典\n",
    "\n",
    "\n",
    "## 概述： 字典是一种 可变的容器模型 ，可存储任意类型对象\n",
    "## 字典的每个键值之间用 ：冒号分割；每个键值对之间用逗号分隔，整个字典写在花括号{}中。\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "|序号|字典的方法|用法|使用结果|注意事项|\n",
    "|----|----------|----|--------|--------|\n",
    "|1|创建字典|dict = {'zh': '2002', 'sq':'2003'}|zh: 2002,sq:2003|值可以取任意数据类型，而键不可变|\n",
    "|2|访问字典里的值|print \"dict['zh']: \", dict['zh']或print \"dict[sq]: \", dict['sq']|dict['zh']: 2002或dict['sq']: 2003|若字典里没有键又访问数据，则会报错|\n",
    "|3|修改字典(更新、添加）|dict['zh'] = 2003(更新）dict['zhsq'] = 20022003（添加）|dict['zh']: 2003 dict['zhsq']: 20022003|注意符号的书写|\n",
    "|4|删除字典元素|del dict['zh'] dict.clear() del dict|剩余或清空或报错|注意需要删除的条目|\n",
    "|5|返回一个字典的浅复制|dict.copy() dict1 = {'name': 'zh', 'age': 19} dict2 = dict1.copy() print \"New Dictinary : %s\" % str(dict2)|New Dictinary : {'age': 19, 'name': 'zh'}|注意符号和%|\n",
    "|6|fromkeys创建新字典|dict.fromkeys(seq[, value]) seq--字典键值列表 value--可选参数，设置键序列（seq）的值 seq = （'Google', 'Runoob', 'Taobao'） dict = dict.fromkeys(seq) print \"新字典为 ：%s\" % str(dict) dict = dict.fromkeys(seq, 10) print \"新字典为 ：%s\" % str(dict）|新字典为 ：{'Google': None, 'Taobao': None, 'Runoob' : None} 新字典为： {'Google':10, 'Taobao': 10, 'Runoob': 10}|注意之间的关系|\n",
    "|7|dict.get(key,default=None)返回指定键的值|dict = {'Name': 'Runoob', 'Age': 27} print \"Value : %s\" % dict.get('Age') print \"Value\" : %s\" % dict.get('Sex', \"Not Available\")|Value : 27 Value : Not Available|如果字典里面嵌套有字典，无法通过 get() 直接获取 value；不能加 default=|\n",
    "|8|如果键在字典dict里返回true，否则返回false（dict.has_key（key.))|dict = {'Name': 'Zara', 'Age': 7} print \"Value : %s\" %  dict.has_key('Age') print \"Value : %s\" %  dict.has_key('Sex')|Value : True Value : False|key -- 要在字典中查找的键。|\n",
    "|9|dict.items()|以列表返回可遍历的(键, 值) 元组数组 dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'} print \"字典值 字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.runoob.com')]Google www.google.comtaobao www.taobao.comRunoob www.runoob.com: %s\" % dict.items() for key,values in  dict.items(): print key,values|字典值 [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob','www.runoob.com')]Google www.google.comtaobao www.taobao.comRunoob www.runoob.com|返回可遍历的(键, 值) 元组数组。|\n",
    "|10|dict.keys()|) 函数以列表返回一个字典所有的键。dict = {'Name': 'Zara', 'Age': 7} print \"Value : %s\" %  dict.keys()|Value : ['Age', 'Name']|注意符号|\n",
    "|11|dict.values()|返回字典中的所有值。dict = {'Name': 'Zara', 'Age': 7} print \"Value : %s\" %  dict.values()|Value : [7, 'Zara']|区别于key|\n",
    "|12|pop(key[,default])|key: 要删除的键值 default: 如果没有 key，返回 default 值 site= {'name': '菜鸟教程', 'alexa': 10000,'url':'www.runoob.com'}pop_obj=site.pop('name') print pop_obj |输出 ：菜鸟教程|注意pop书写|\n",
    "|13|popitem()|site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'}pop_obj=site.popitem()print(pop_obj)print(site）|('url','www.runoob.com'){'alexa': 10000, 'name': '\\xe8\\x8f\\x9c\\xe9\\xb8\\x9f\\xe6\\x95\\x99\\xe7\\xa8\\x8b'}|区别POPkey|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
